package com.itqf.controller;

import com.itqf.entity.TbItem;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/12/23
 * @Time: 上午10:47
 */
@RestController
public class TbItemController {


    @Value("${server.port}")
    private  int port;


    @RequestMapping("/find/{id}")
    public TbItem findById(@PathVariable long id){
        System.out.println("port:"+port);

        if (id==1){
            throw  new RuntimeException("参数类型错误！！");
        }

        TbItem tbItem = new TbItem();
        tbItem.setId(id);
        tbItem.setPrice(100);
        tbItem.setTitle("山寨机");
        tbItem.setSellPoint("就是牛！！");
        return  tbItem;
    }

    @RequestMapping("/findAll")
    public TbItem findAll(){
        System.out.println("port:"+port);

        try {//为了演示负载均衡  根据调用的服务的响应时间来设置权重
            //时间越长
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        TbItem tbItem = new TbItem();
        tbItem.setId(1);
        tbItem.setPrice(100);
        tbItem.setTitle("山寨机");
        tbItem.setSellPoint("就是牛！！");
        return  tbItem;
    }

    @Value("${version}")
    private String  version;

    @RequestMapping("/api")
    public  String  api() throws  Exception{

        Thread.sleep(2000);
        //int i = 10/0;  error  zuul  Error

        return "版本是："+version;
    }



}
